import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import hilog from '@ohos.hilog';
import UIAbility from '@ohos.app.ability.UIAbility';
import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
import testNapi from 'libentry.so';
import thermal from '@ohos.thermal';
import { FileUtils } from '../utils/FileUtils';

const TAG = 'testTag';
const DOMAIN = 0x0000;

export default class EntryAbility extends UIAbility {
  async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): Promise<void> {
    hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate');

    // FileUtils .readRawFile(this.context, "project.cl").then(content =>{
    //   hilog.info(DOMAIN, TAG, '11File content: %{public}s', content);
    // });

    const fileNames: string[] = ['project.cl', 'transform_vec3.cl', 'add_two_numbers.cl'];
    FileUtils.batchCopyRawFiles(this.context, fileNames);

    // FileUtils.readFromSandbox(this.context, "project.cl");
    // FileUtils.readAndPrintFile(this.context, "project.cl");
  }


  onDestroy(): void {
    hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onDestroy');
  }


  onWindowStageCreate(windowStage: window.WindowStage): void {
    // Main window is created, set main page for this ability
    hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate');

    windowStage.loadContent('pages/Index', (err) => {
      if (err.code) {
        hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
        return;
      }
      hilog.info(DOMAIN, TAG , 'Succeeded in loading the content.');
      // hilog.info(DOMAIN, TAG, 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
      // hilog.info(DOMAIN, TAG, 'hello world %{public}s', testNapi.helloWorld());
      // hilog.info(DOMAIN, TAG, 'get number %{public}d', testNapi.getNumber());
      hilog.info(DOMAIN, TAG, 'test Opencl %{public}d', testNapi.testOpencl());
      testNapi.clMethodPath(this.context.filesDir);
    });

  }

  onWindowStageDestroy(): void {
    // Main window is destroyed, release UI related resources
    hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy');
  }

  onForeground(): void {
    // Ability has brought to foreground
    hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onForeground');
  }

  onBackground(): void {
    // Ability has back to background
    hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onBackground');
  }
};
